var app = getApp()
const util = require('../../../utils/util.js')
const catVoice = wx.createInnerAudioContext({});
 Page({
  data: { 
    catlist: [],
    screenWidth: 0,
    screenHeight: 0,
    imgwidth: 0,
    imgheight: 0,
    url: app.globalData.url,
    configurl: app.globalData.configurl,
    imgUrls: [],
    currentIndex:0,
    catinfo: {},
    cats: {},
    catconfig: app.globalData.config,
    openVedio: false, //视频是否全屏
    openVoice: false,
    isPlayVoice: false
  },

  onPullDownRefresh:function(){
    wx.stopPullDownRefresh()
  },

  //弹出视频图层。播放视频
  showVideo(e) {
    var _this = this;
    _this.videoContext.requestFullScreen()
    // setTimeout(function() {
    //   _this.videoContext.play()
    // }, 500)
    console.log(_this.data.configurl + _this.data.catinfo.vedio);

    // var videoContext = wx.createVideoContext('myvideo', this);
    // videoContext.requestFullScreen();

    this.setData({
      openVoice: false,
      openVedio: true
    })

  },
  showVoice(e) {
    var _this = this;
    _this.setData({
      openVoice: !_this.data.openVoice,
      openVedio: false,
      isPlayVoice: !_this.data.isPlayVoice,
    });
    setTimeout(function() {
      if(_this.data.isPlayVoice){
        catVoice.play();
      }else{
        catVoice.stop();
      }
        
    }, 500)
  },

  onReady: function() {
    this.videoContext = wx.createVideoContext('catvedio', this)
    this.audioCtx = wx.createInnerAudioContext()
  },

  closeVideo() {
    //执行退出全屏方法
    this.videoContext.exitFullScreen();
  },

  //转发跳转页面设置
  onLoad: function (options) {
    var _this = this;
    console.log(app.globalData.catinfo);
    var catinfo = JSON.parse(options.catinfo);
    catVoice.src = _this.data.configurl + catinfo.voice;
    console.log(catVoice.src);

    _this.setData({
      imgUrls:catinfo.img,
      catinfo:catinfo,
      catconfig:app.globalData.config,
      cats: app.globalData.cats
    });
    // _this.setData({
    //   type:options.cattype,
    //   state:options.state
    // });
    // util.getCatConfig(app.globalData.config + "config/cats.json").then( res => {
    //   _this.setData({
    //     catlist: res
    //   })
    // })
    if (options.pageId) {
      wx.navigateTo({
        url: '/pages/cats/' + options.pageId + '/' + options.pageId,
      })
    }
  },

  //转发此页面的设置
  onShareAppMessage: function (ops) {
    if (ops.from === 'button') {
      // 来自页面内转发按钮
      console.log(ops.target)
    }
    return {
      path: 'pages/index/index',  // 路径，传递参数到指定页面。
      success: function (res) {
        // 转发成功
        console.log("转发成功:" + JSON.stringify(res));
      },
      fail: function (res) {
        // 转发失败
        console.log("转发失败:" + JSON.stringify(res));
      }
    }
  },

  // 搜索栏输入名字后页面跳转
  bindconfirmT: function (e) {
    console.log("e.detail.value");
    if(e.detail.value) {
    
    wx.navigateTo({
      url: '/pages/cats/' + e.detail.value + '/' + e.detail.value,
    })
  }
  },

  naviToFriend:function(e){
    wx.navigateTo({
      url: '/pages/index/catdetailed/catdetailed?catinfo=' + JSON.stringify(e.currentTarget.dataset.item)
    })
   }


})

